package dfs;

public class Demo20250728 {
    /**
     * 计算布尔二叉树的值
     *
     * @param root 根节点
     * @return 布尔值
     */
    public boolean evaluateTree(TreeNode root) {
        if (root.right == null && root.left == null) return root.val == 0 ? false : true;
        boolean left = evaluateTree(root.left);
        boolean right = evaluateTree(root.right);
        if (root.val == 2) return left || right;
        else return left && right;
    }
}


class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
